package com.linksfield.topup.config.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * xaingyi
 *
 * @author: lm
 * @date: 2019-11-21 15:40
 */
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(description = "响应数据")
@ToString
public class ResultDataDto implements Serializable {

    private static final long serialVersionUID = 1366124514345165778L;
    /**
     * S-操作成功
     */
    public static final String CODE_OPERATE_SUCCESS = "S";

    /**
     * F-操作失败
     */
    public static final String CODE_OPERATE_FAILURE = "F";


    public static ResultDataDto addAddSuccess() {
        return new ResultDataDto(CODE_OPERATE_SUCCESS, "新增成功");
    }

    public static ResultDataDto addUpdateSuccess() {
        return new ResultDataDto(CODE_OPERATE_SUCCESS, "更新成功");
    }

    public static ResultDataDto addDeleteSuccess() {
        return new ResultDataDto(CODE_OPERATE_SUCCESS, "删除成功");
    }

    public static ResultDataDto addOperationSuccess() {
        return new ResultDataDto(CODE_OPERATE_SUCCESS, "成功");
    }

    public static ResultDataDto addOperationSuccess(String message) {
        return new ResultDataDto(CODE_OPERATE_SUCCESS, message);
    }

    public static ResultDataDto addOperationFailure() {
        return new ResultDataDto(CODE_OPERATE_FAILURE, "操作失败");
    }

    public static ResultDataDto addOperationFailure(String message) {
        return new ResultDataDto(CODE_OPERATE_FAILURE, message);
    }

    public static ResultDataDto operationUnAuthority() {
        return new ResultDataDto(CODE_OPERATE_FAILURE, "你无此操作权限，请联系管理员");
    }

    public static ResultDataDto addNotRemoteResponse() {
        return new ResultDataDto(CODE_OPERATE_FAILURE, "远程服务没有响应,请稍后再试!");
    }

    public ResultDataDto() {
        super();
    }

    public ResultDataDto(String operateCode, String message) {
        super();
        this.message = message;
        this.operateCode = operateCode;
    }

    public ResultDataDto(String message) {
        super();
        this.operateCode = CODE_OPERATE_SUCCESS;
        this.message = message;
    }

    /**
     * 返回单个实体
     */
    public ResultDataDto(Object entity) {
        super();
        this.operateCode = CODE_OPERATE_SUCCESS;
        this.data = entity;
    }

    /**
     * 返回集合类型
     */
    public ResultDataDto(List<?> list) {
        super();
        this.operateCode = CODE_OPERATE_SUCCESS;
        this.data = list;
    }

    /**
     * 返回Map集合类型
     */
    public ResultDataDto(Map<String, Object> map) {
        super();
        this.operateCode = CODE_OPERATE_SUCCESS;
        this.data = map;
    }

    /**
     * 返回分页集合
     */
    public ResultDataDto(List<?> list, PageAndSort pageAndSort) {
        super();
        this.operateCode = CODE_OPERATE_SUCCESS;
        this.data = list;
        this.pageAndSort = pageAndSort;
    }

    @ApiModelProperty(value = "操作代码,(S)成功(F)失败")
    private String operateCode;

    /**
     * 消息
     */
    @ApiModelProperty(value = "消息", readOnly = true)
    private String message;

    /**
     * 结果数据，单个实体 或 List<T>
     */
    @ApiModelProperty(value = "结果数据", readOnly = true)
    private Object data;

    /**
     * 分页数据
     */
    //@ApiModelProperty(hidden = true)
    @ApiModelProperty(value = "分页数据", readOnly = true)
    private PageAndSort pageAndSort;
}
